<?

/**
* local collection functions of tocmenu_11
*
* @author Adesanto Asman
* @version 1.0
* @license Free
* @copyright Copyright (c)2007, Adesanto Asman
* @package CLFetchers
*
*/

/**
* @package CLFetchers
*
*/
class CLFetchers{

  /**
   * list of data header
   *
   * @param object  $Db
   * @param integer $modelId
   * @param string  $srcDb
   * @param integer $nHeader
   * @param array   $lstHeader
   */
  function fetchLstDataHeader(&$Db,
                              &$modelId,
                              &$SourceDb,
                              &$nHeader,
                              &$lstHeader){

    $query  = "SELECT H.MODEL,
                      H.MODEL_ID,
                      T.TYPE_NAME,
                      H.UNIT,
                      H.SER_NUMBER

               FROM ".$SourceDb->fetchValue("srcDbHdr")."     H,
                    ".$SourceDb->fetchValue("srcDbMstType")." T

               WHERE  H.MODEL_ID='".$modelId."'
                      AND T.TYPE=H.TYPE ";

    $Db->execFetchQuery($query,
                        $nHeader,
                        $lstHeader);
  }

  /**
   * list of transaction
   *
   * @param object  $Db
   * @param string  $condt
   * @param string  $srcDbHdr
   * @param integer $nrows
   * @param array   $res
   */
  function fetchLstTransaction(&$Db,
                                $condt,
                               &$srcDb,
                               &$nrows,
                               &$result){

    $query	= "SELECT *
               FROM ".$srcDb."
               ".$condt."	 ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);
  }

  /**
   * model' type
   *
   * @param objecy  $Db
   * @param string  $srcDb
   * @param array   $lstMdlType
   */
  function fetchModelType(&$Db,
                           $srcDb,
                          &$lstMdlType){

    $query	= "SELECT TYPE_NAME
               FROM ".$srcDb."
               ORDER BY TYPE_NAME ASC	 ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    $lstMdlType = $result["TYPE_NAME"];
  }

  /**
   * type id
   *
   * @param object  $Db
   * @param string  $typeName
   * @param string  $srcDb
   * @param integer $typeId
   */
  function fetchTypeId(&$Db,
                       &$typeName,
                       &$srcDb,
                       &$typeId){

    $query	= "SELECT TYPE
               FROM ".$srcDb."
               WHERE	TYPE_NAME='".$typeName."' ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    $typeId = $result["TYPE"][0];
  }

  /**
   * last model id
   *
   * @param object  $Db
   * @param string  $srcDb
   * @param integer $modelId
   */
  function fetchLastModelId(&$Db,
                             $srcDb,
                            &$modelId){

    $query	= "SELECT MODEL_ID
               FROM ".$srcDb."
               ORDER BY MODEL_ID DESC ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    if($nrows > 0){

      $modelId = $result["MODEL_ID"][0] + 1;
    }else{

      $modelId = 1;
    }
  }
}

?>